package com.shreecon.lms.persistancy;

import org.hibernate.Session;
import org.hibernate.cfg.Configuration;

/**
 * The Class HibernateAccessUtil.
 * 
 * @author Santhosh. Modified on Aug 13, 2011
 */
public class HibernateAccessUtil {

    /** The Constant HIBER_NATE_CONFIG. */
    private static final String HIBER_NATE_CONFIG = "hibernate.cfg.xml";
    
    /** The Constant hiberNateAccessUtil. */
    private static final HibernateAccessUtil hiberNateAccessUtil = new HibernateAccessUtil();

    /**
     * Instantiates a new hibernate access util.
     */
    private HibernateAccessUtil() {

    }

    /**
     * Gets the single instance of HibernateAccessUtil.
     * 
     * @return single instance of HibernateAccessUtil
     */
    public static HibernateAccessUtil getInstance() {
        return hiberNateAccessUtil;
    }

    /**
     * Gets the session.
     * 
     * @return the session
     */
    public Session getSession() {
        return new Configuration().configure(HIBER_NATE_CONFIG).buildSessionFactory().openSession();
    }

    /**
     * Close session.
     * 
     * @param session
     *            the session
     */
    public void closeSession(final Session session) {
        if (session != null) {
            session.close();
        }
    }

}
